package cn.net.vote.util;

public class JobPreparationUtil {
	
	
	//------------有关计算报备实际时长的方法------------
	
	//开始时间,结束时间范围外  算为有效时间  (工作时外有效, 计算假期)
	/**
	 * 
	 * @param isHoliday 0非1是节假日
	 * @param startSecs 开始时间当天秒数
	 * @param onDutySecs 规定上班秒数
	 * @param endSecs 结束时间当天秒数
	 * @param offDutySecs 规定下班秒数
	 * @return 返回总共秒数
	 */
	public double calOutside(int isHoliday,int startSecs,int onDutySecs,int endSecs,int offDutySecs){
		double secs = 0;
		if (isHoliday == 0) {
			System.out.println("非节假日!");
			if (startSecs < onDutySecs) {
				if (endSecs < onDutySecs) {
					secs += endSecs - startSecs;
				} else if (endSecs >= onDutySecs && endSecs <= offDutySecs) {
					secs += onDutySecs - startSecs;
				} else if (endSecs > offDutySecs) {
					secs += (onDutySecs - startSecs) + (endSecs - offDutySecs);
				}

			} else if (startSecs >= onDutySecs && startSecs <= offDutySecs) {
				if (endSecs >= onDutySecs && endSecs <= offDutySecs) {
					secs += 0;
				} else if (endSecs > offDutySecs) {
					secs += endSecs - offDutySecs;
				}
			} else if (startSecs > offDutySecs) {
				if (endSecs > offDutySecs) {
					secs += endSecs - startSecs;
				}
			}

		} else {
			System.out.println("是节假日!");
			secs += endSecs - startSecs;
		}
		
		return secs;
		
	}
	
	//开始时间,结束时间范围内  算为有效时间  (工作时内有效,当然假期时间不算)
	public double calInside(int isHoliday,int startSecs,int onDutySecs,int endSecs,int offDutySecs){
		double secs = 0;
		if (isHoliday == 0) {
			if (startSecs < onDutySecs) {
				if (endSecs < onDutySecs) {
					secs += 0;
				} else if (endSecs >= onDutySecs && endSecs <= offDutySecs) {
					secs += endSecs - onDutySecs;
				} else if (endSecs > offDutySecs) {
					secs += offDutySecs - onDutySecs;
				}

			} else if (startSecs >= onDutySecs && startSecs <= offDutySecs) {
				if (endSecs >= onDutySecs && endSecs <= offDutySecs) {
					secs += endSecs - startSecs;
				} else if (endSecs > offDutySecs) {
					secs += offDutySecs - startSecs;
				}
			} else if (startSecs > offDutySecs) {
				if (endSecs > offDutySecs) {
					secs += 0;
				}
			}
		} else {
			secs += 0;
		}
		return secs;
	}



}
